package au.com.carboncycle.gb.engine.screen;

import java.awt.Color;
import java.awt.Font;
import java.awt.Point;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import org.apache.log4j.Logger;

import au.com.carboncycle.gb.engine.GameClock;
import au.com.carboncycle.gb.engine.Input.Key;
import au.com.carboncycle.gb.engine.Screen;
import au.com.carboncycle.gb.engine.entities.BadGuySprite;
import au.com.carboncycle.gb.engine.entities.HeroSprite;
import au.com.carboncycle.gb.engine.entities.Sprite;
import au.com.carboncycle.gb.engine.entities.WorldEntity;
import au.com.carboncycle.gb.engine.graphics.GBRenderer;
import au.com.carboncycle.gb.engine.resources.Art;

public class GameScreen extends Screen {

	private static final Logger log = Logger.getLogger(GameScreen.class);
	
	WorldEntity world;
	
	HeroSprite heroSprite;
	

	public GameScreen () {
		heroSprite = new HeroSprite(new Point(0,400));
		
		world = new WorldEntity(heroSprite);
	}
	
	
	@Override
	public void render(GBRenderer renderer) {
        renderer.drawBackground(Art.background);
        
		
		String msg = "General Brawler 1.0";
		renderer.drawString(msg, 20, 100, 50, Font.decode("verdana-bold-30"), Color.WHITE);

		
        renderer.drawEntity(heroSprite);
        
        for (Sprite sprite : world.getBadGuys()) {
        	renderer.drawEntity(sprite);
        }
        
        world.render(renderer); //only used to trace debugging shapes into the game screen
	}

	@Override
	public void tick(List<Key> input, GameClock gameClock) {
		if (log.isTraceEnabled() && !input.isEmpty())
			log.trace(input.toString());		
		
		world.tick(gameClock);
		
		moveHero(input);
		
		
		//add guy to screen if needed

		
		
		
		
		
		
	}


	private void moveHero(List<Key> input) {
		if (input.contains(Key.LEFT)) {
			heroSprite.move(new Point(-12, 0), world);
		}
		
		if (input.contains(Key.RIGHT)) {
			heroSprite.move(new Point(12, 0), world);
		}
		
		if (input.contains(Key.UP)) {
			heroSprite.move(new Point(4, -8), world);
		}
		
		if (input.contains(Key.DOWN)) {
			heroSprite.move(new Point(-4, 8), world);
		}
	}

	
	
}
